"""
    使用到的一些函数
"""
import random
import string
import time

import requests


# 国内代理
def get_china_proxy():
    while True:
        try:
            address = requests.get(
                f"http://cce.10404.fore-end.flight.api.21kv.com/proxy/get/{random.choice(['u2', 'sq', 'jq'])}",
                # f"http://cce.10404.fore-end.flight.api.21kv.com/proxy/get/{random.choice(['u2', 'sq', 'jq'])}",
                timeout=5).text
            if address != '':
                proxys = f"http://{address}"
                proxyDict = {
                    "http": proxys,
                    "https": proxys,
                }
                return proxyDict
        except Exception as e:
            print("获取代理失败")
            time.sleep(1)


# 国外流量代理
def get_abroad_proxy():
    # 定义字符集，包括大小写字母和数字
    characters = string.ascii_letters + string.digits
    # 随机选择字符并生成长度为length的字符串
    # random_string = ''.join(random.choice(characters) for _ in range(length=10))
    random_string = ''.join(random.choice(characters) for _ in range(10))
    country = random.choice(["jp", "sg", "us", "hk"])
    # country = "hk"
    proxy = {
        "http": f"http://user-fetchu2test123-region-{country}-sessid-{random_string}-sesstime-3-keep-true:fetchu2test123@119.8.170.26:24600",
        "https": f"http://user-fetchu2test123-region-{country}-sessid-{random_string}-sesstime-3-keep-true:fetchu2test123@119.8.170.26:24600"
    }
    return proxy


# 传入列表,返回打乱后的内容
def shuffle_middle_part(s):
    # 提取前两位和最后一位
    prefix = s[:2]
    suffix = s[-1]
    # 提取中间部分
    middle = s[2:-1]
    # 将中间部分转换为列表并打乱顺序
    middle_list = list(middle)
    random.shuffle(middle_list)
    shuffled_list = '-'.join(prefix + middle_list + [suffix])

    return shuffled_list


if __name__ == '__main__':
    proxy = get_abroad_proxy()
    print(proxy)
